using Godot;
using System;
using Godot.Collections;

public partial class GameCamera : Camera2D
{
	private Vector2 TargetPosition;

	private Vector2 lastPosition;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		MakeCurrent();
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		this.AcquireTarget();
		double a = 1 - Math.Exp( - delta * 20);
		GlobalPosition = GlobalPosition.Lerp(TargetPosition,(float)a);

		if(lastPosition != GlobalPosition){
			// GD.Print(GlobalPosition,a);
		}
		lastPosition = GlobalPosition;
		
	}

	public void AcquireTarget(){
		Array<Node> playerNodes = GetTree().GetNodesInGroup("player");
		if(playerNodes.Count > 0){
			Node2D player = playerNodes[0] as Node2D;
			
			TargetPosition = player.GlobalPosition;
		}
	}
}
